import { useParams } from 'react-router-dom'
import data from '../data.js'
const limit = 5;

export default function List() { 
  const { t = 'all', p = 1 } = useParams();
  let allData = [];
  if (t==='all') {
    allData = [...data['good'], ...data['share'], ...data['ask']];
  } else {
    allData = data[t]
  }
  let starIndex = (Number(p) - 1) * limit;
  let endIndex = starIndex + limit;

  let nowData = allData.filter((item,index)=>(index>=starIndex&&index<endIndex))

  return (
    <ul className="list">
      {nowData.length?nowData.map(item=><li key={item.id}>{item.title}</li>):'暂无数据'}
    </ul>
  )
}